package com.totoro.springboot.kafka_demo.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * Created by Niki on 2018/5/12 10:45
 */
@Component
@Slf4j
public class MessageListener {
    @KafkaListener(topics = {"kafkaDemo"})
    public void listener(ConsumerRecord record) {
        Optional kafkaMessage = Optional.ofNullable(record.value());
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();
            log.info("record topic:{}, message is {}", "kafkaDemo", message);
        }
    }
}
